// Copyright Epic Games, Inc. All Rights Reserved.

#include "MultiplayerSessions.h"

#include "OnlineSubsystem.h"
#include "Interfaces/OnlineSessionInterface.h"

#define LOCTEXT_NAMESPACE "FMultiplayerSessionsModule"

DEFINE_LOG_CATEGORY(MultiplayerSession)

void FMultiplayerSessionsModule::StartupModule()
{
	// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
}

void FMultiplayerSessionsModule::ShutdownModule()
{
	// This function may be called during shutdown to clean up your module.  For modules that support dynamic reloading,
	// we call this function before unloading the module.

	//destroy session if have one
	auto Subsystem = IOnlineSubsystem::Get();
	if (!Subsystem)
	{
		return;
	}


	auto SessionInterface = Subsystem->GetSessionInterface();
	if (SessionInterface.IsValid())
	{
		auto ExistingSession = SessionInterface->GetNamedSession(NAME_GameSession);
		if (ExistingSession != nullptr)
		{
			SessionInterface->DestroySession(NAME_GameSession);
		}
	}
}

#undef LOCTEXT_NAMESPACE

IMPLEMENT_MODULE(FMultiplayerSessionsModule, MultiplayerSessions)
